home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-18 | 2.8 KB | 108 lines |
- /*
- * @(#)ISAPIOutputStream.java 1.7 97/05/14
- *
- * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This software is the confidential and proprietary information of Sun
- * Microsystems, Inc. ("Confidential Information"). You shall not
- * disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Sun.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
- * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- *
- * CopyrightVersion 1.0
- */
-
- package sun.servlet.isapi;
-
- import java.io.OutputStream;
- import java.io.IOException;
- import sun.servlet.http.HttpOutputStream;
-
- /**
- * This class implements an output stream for writing ISAPI response data.
- *
- * @version 1.7, 05/14/97
- * @author David Connelly
- * @author Jongyoon Lee
- */
- class ISAPIOutputStream extends HttpOutputStream {
- /*
- * The Extension Control Block (ECB) for this response.
- */
- private ISAPIConnection conn;
-
- /**
- * Initializes the output stream with the ECB for this response.
- */
- public void init(ISAPIConnection conn) {
- this.conn = conn;
- next();
- }
-
- /**
- * Resets the output stream to an uninitialized state.
- */
- public void resets() {
- super.resets();
- this.conn = null;
- }
-
- /**
- * Flushes output stream bytes.
- */
- protected void flushBytes() throws IOException {
- if (!committed) {
- if (obs != null) {
- obs.update(null, this);
- }
- }
- committed = true;
- if (count > 0) {
- conn.writeClient(buf, 0, count);
- count = 0;
- }
- }
-
- /**
- * Checks the output stream for a pending IOException that needs to be
- * thrown, a content length that has been exceeded, or observers that
- * need to be notified.
- * @param len the number of bytes about to be written
- */
- protected void check(int len) throws IOException {
- // check for observers that need notifying.
- if (limit < 0) {
- if (total > 0) {
- throw new InternalError();
- }
- // set the limit so that content length won't be exceeded
- if (length != -1) {
- limit = length;
- } else {
- limit = Integer.MAX_VALUE;
- }
- }
- // check if content length exceeded
- if (total + len > limit) {
- limit = -1;
- throw except = new IOException("write past end of stream");
- }
- }
-
- /*
- * Writes to the underlying stream
- */
- protected void writeOut(byte[] buf, int offset, int len)
- throws IOException
- {
- conn.writeClient(buf, offset, len);
- }
- }
-